﻿using System;
using System.Collections.Generic;

namespace Birkelund.QueryStrings.Internals
{
    internal class AlphabeticWithCheckSumLastComparer : IComparer<string>
    {
        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. Note that checksum token will always be sorted as the last token
        /// </summary>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        /// <returns>
        /// Value Condition Less than zero<paramref name="x"/> is less than <paramref name="y"/>.
        /// Zero<paramref name="x"/> equals <paramref name="y"/>.
        /// Greater than zero<paramref name="x"/> is greater than <paramref name="y"/>.
        /// </returns>
        public int Compare(string x, string y)
        {
            //if (x == null || y == null)
            //{
            //    return 0;
            //}
            if (x == CheckSumKeyToken.Instance.KeyName || y == CheckSumKeyToken.Instance.KeyName)
            {
                return -2; // checksumkey must always be sorted as the last entry
            }
            else
            {
                return StringComparer.InvariantCultureIgnoreCase.Compare(x, y);
            }
        }
    }
}
